import { reqGetGoodsInfoData } from "@/api";

const state = {
  goodsInfo: {},
};

const actions = {
  async getGoodsInfoData({ commit }, searchParams) {
    const result = await reqGetGoodsInfoData(searchParams);
    if (result.code === 200) {
      commit("SAVE_GOODS_INFO_DATA", result.data);
    }
  },
};

const mutations = {
  SAVE_GOODS_INFO_DATA(state, goodsInfo) {
    state.goodsInfo = goodsInfo;
  },
};
const getters = {
  // 1. 商品列表
  goodsList(state) {
    return state.goodsInfo.goodsList || [];
  },
  // 2. 品牌列表
  trademarkList(state) {
    return state.goodsInfo.trademarkList;
  },
  // 3. 属性列表
  attrsList(state) {
    return state.goodsInfo.attrsList;
  },
};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
};
